ENT.Type = "anim"
ENT.PrintName			= "Nerve Gas Grenade"
ENT.Author			= "Generic Default did most of this, i just modified it"
ENT.Contact			= ""
ENT.Purpose			= ""
ENT.Instructions			= ""


if SERVER then

AddCSLuaFile( "shared.lua" )

function ENT:Initialize()

	self.Entity:SetModel("models/healthvial.mdl")
	self.Entity:SetMaterial("models/weapons/gv/nerve_vial.vmt")
	self.Entity:PhysicsInit( SOLID_VPHYSICS )
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
	self.Entity:SetSolid( SOLID_VPHYSICS )
	self.Entity:DrawShadow( false )
	
	self.backflightvector = self.Entity:GetForward() * (-5)
	
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
	phys:SetMass(4)
	phys:Wake()
	end
	self:Think()
end

 function ENT:Think()

	self.Entity:NextThink( CurTime() )
	return true
end

/*---------------------------------------------------------
PhysicsCollide
---------------------------------------------------------*/
function ENT:PhysicsCollide(data,phys)

	--self.timeleft = CurTime() + 20
	
	if data.Speed > 50 then
		self.Entity:EmitSound(Sound("GlassBottle.Break"))
	end
	
	self:BreakVial()
	
end

function ENT:BreakVial()

	local pos = self.Entity:GetPos()
	
	-- local gas = ents.Create("m9k_released_gas")
	-- gas:SetPos(pos)
	-- gas:SetOwner(self.Owner)
	-- gas:Spawn()
	-- gas:SetVar("gassed", 0) 
	
	local gas = EffectData()
		gas:SetOrigin(pos)
		gas:SetEntity(self.Owner) //i dunno, just use it!
		gas:SetScale(1)//otherwise you'll get the pinch thing. just leave it as it is for smoke, i'm trying to save on lua files dammit!
	util.Effect("m9k_released_nerve_gas", gas)
	
	local poison = ents.Create("m9k_released_poison")
	poison:SetPos(pos )
	poison:SetOwner(self.Owner)
	poison.Owner = self.Owner
	poison.Big = false
	poison:Spawn()
	
	self.Entity:Remove()

end

/*---------------------------------------------------------
OnTakeDamage
---------------------------------------------------------*/
function ENT:OnTakeDamage( dmginfo )
	if not IsValid(dmginfo) then return end if not IsValid(dmginfo:GetInflictor()) then return end
	if dmginfo:GetInflictor() == "m9k_released_poison" then return end
	self:BreakVial()
	self.Entity:EmitSound(Sound("GlassBottle.Break"))
end

end

if CLIENT then

 function ENT:Draw()             
 self.Entity:DrawModel()       // Draw the model.   
 end

end